package com.ygou.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygou.mapper.AnnouncementMapper;
import com.ygou.pojo.Announcement;
import com.ygou.pojo.AnnouncementExample;
import com.ygou.pojo.AnnouncementExample.Criteria;
import com.ygou.service.AnnouncementService;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {
	@Autowired
	AnnouncementMapper announcementMapper;

	// 添加公告
	@Override
	public boolean insert(Announcement record) {
		record.setCreatetime(new java.util.Date());
		return announcementMapper.insert(record) > 0;
	}

	// 刪除公告
	@Override
	public boolean deleteByPrimaryKey(Integer annid) {
		return announcementMapper.deleteByPrimaryKey(annid) > 0;
	}

	// 修改公告
	@Override
	public boolean updateByPrimaryKey(Announcement record) {
		return announcementMapper.updateByPrimaryKey(record) > 0;
	}

	// 根据主键查询
	@Override
	public Announcement selectByPrimaryKey(Integer annid) {
		return announcementMapper.selectByPrimaryKey(annid);
	}

	// 根据条件查询(两表链接)
	@Override
	public List<Announcement> findByWhere(String title, Integer annid) {
		AnnouncementExample example = new AnnouncementExample();
		example.setOrderByClause("createtime desc");
		Criteria c = example.createCriteria();
		if (title != null && !"".equals(title)) {
			c.andAnntitleLike("%" + title + "%");
		}
		if (annid != null && !"".equals(annid)) {
			c.andAnnidEqualTo(annid);
		}
		return announcementMapper.findByWhere(example);
	}

	@Override
	public List<Announcement> selectByExample() {
		AnnouncementExample example = new AnnouncementExample();
		example.setOrderByClause("createtime desc");
		return announcementMapper.selectByExample(example);
	}


}
